package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * @author chenwenjie
 *认证邮箱的有效性
 */
public class UserAccountEmailUpdateRequest extends Request {
	
	/**
	 * 用户id
	 */
	private int userId;
	
	/**
	 * 客户邮箱
	 */
	private String email;
	/**
	 * 校验码
	 */
	private String code;

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.email = requestInfo.getParameter(ApiUrlParamEnum.email.getParamName(), "");
		if (userId < 1) {
			throw new RequestIllegalException("用户id有误");
		}
		if (StringUtil.isEmpty(email)) {
			throw new RequestIllegalException("邮箱不能都空");
		}
		if (!StringUtil.isEmpty(email) && !StringUtil.isEmail(email)) {
			throw new RequestIllegalException("邮箱格式有误");
		}
	}

}
